<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>生态瞬时评估 - 主页</title>

    <meta name="keywords" content="">
    <meta name="description" content="">

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

    <link rel="shortcut icon" href="../favicon.ico">
    <link href="../css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="../css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="../css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="../css/animate.css" rel="stylesheet">
    <link href="../css/style.css?v=4.1.0" rel="stylesheet">
</head>
<body>
<div class="wrapper wrapper-content animated fadeInRight">
    <!--<div class="row">-->
        <!--<div class="col-sm-3 col-sm-offset-9"><a class="btn btn-primary">详情</a></div>-->
    <!--</div>-->
    <div class="row">
        <h3 class="col-sm-offset-3 col-sm-6 text-center">答题策略</h3>
    </div>
    <div class="row">
        <div class="col-sm-offset-3 col-sm-6">
            <form class="form-horizontal" style="margin-top: 20px">
                <div class="form-group">
                    <label for="strategy-name" class="col-sm-3 control-label">策略名称：</label>
                    <div class="col-sm-8">
                        <input type="text" placeholder="请输入策略名称" class="form-control" id="strategy-name">
                    </div>
                </div>



                <div class="form-group">
                    <label for="start-time" class="col-sm-3 control-label">开始时间：</label>
                    <div class="col-sm-8">
                        <input type="text" class="laydate-icon form-control layer-date" id="start-time" placeholder="输入开始时间（例如13:30）">
                    </div>
                </div>

                <div class="form-group">
                    <label for="end-time" class="col-sm-3 control-label">结束时间：</label>
                    <div class="col-sm-8">
                        <input type="text" class="laydate-icon form-control layer-date" id="end-time" placeholder="输入结束时间（例如13:30）">
                    </div>
                </div>

                <div class="form-group">
                    <label for="frequency" class="col-sm-3 control-label">答题频率：</label>
                    <div class="col-sm-8">
                        <input type="text" placeholder="请输入答题频率" class="form-control" id="frequency">
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">类型：</label>
                    <div class="col-sm-8" id="Stype">
                        <div class="radio-inline i-checks">
                            <label>
                                <input type="radio" value="0" name="answer-type"> <i></i> 固定</label>
                        </div>
                        <div class="radio-inline i-checks">
                            <label>
                                <input type="radio" value="1" name="answer-type"> <i></i> 随机</label>
                        </div>
                    </div>
                </div>
                <div class="col-sm-offset-3 col-sm-8">
                    <!--<input type="button" id="changeBtn" value="确认" class="btn btn-primary btn-block">-->
                </div>
            </form>
        </div>
    </div>

</div>




<script src="../js/jquery.min.js?v=2.1.4"></script>
<script src="../js/bootstrap.min.js?v=3.3.6"></script>
<script src="../js/dateChange.js"></script>
<script src="../js/plugins/layer/laydate/laydate.js"></script>
<!--icheck-->
<script src="../js/plugins/iCheck/icheck.min.js"></script>
<script>
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });

    });
</script>
<script>
    $(document).ready(function () {
        var testId = sessionStorage.getItem("testId");
        var token = sessionStorage.getItem("token");
        $.ajax({
            type:"GET",
            url:"http://123.206.18.189:8080/experiments/"+testId+"/examination_strategy",
            headers:{
                authToken:token
            },
            success:function (res) {
                $("#strategy-name").val(res.name);
                $("#start-time").val(hmDateChange(res.beginTime));
                $("#end-time").val(hmDateChange(res.endTime));
                $("#frequency").val(res.rate);
                var type = res.type;
                if(type == "RANDOM") {
                    $("#Stype input[value='1']").parent().addClass("checked");
                }else{
                    $("#Stype input[value='0']").parent().addClass("checked");
                }
            }
        })
        $("#changeBtn").click(function () {
            var reg = /^[0|1|2]{1}[0-9]{1}:[0-9]{1,2}$/;
            var date = nowDate();
            var beginTime="";
            var endTime = "";
            if(reg.test($("#start-time").val())&&reg.test($("#end-time").val())){
                beginTime = date+" "+$("#start-time").val();

                endTime = date+" "+$("#end-time").val();
                console.log(endTime,beginTime);
            }else{
                alert("开始时间或接受时间格式不正确，请重新输入！");
                return;
            }
            var $strategyName = $("#strategy-name").val();
            var $beginT = timeToTimestamp(beginTime);
            var $endT = timeToTimestamp(endTime);
            var $rate = $("#frequency").val();
            var $type = $("#Stype .checked").find("input").val()==0?"FIXED":"RANDOM";
            var _data = JSON.stringify({"experimentId":testId,"name":$strategyName,"beginTime":$beginT,"endTime":$endT,"offsetTime":10, "rate":$rate, "type":$type});
            console.log(_data);
            if($strategyName == " "||$beginT == " "||$endT == " "||$rate == ""||$type == ""){
                alert("请填写所有信息！");
            }else{
                var r = confirm("是否确认修改答题策略？");
                if(r){
                    $.ajax({
                        type:"PUT",
                        url:"http://123.206.18.189:8080/experiments/"+testId+"/examination_strategy",
                        headers:{
                            authToken:token
                        },
                        contentType:"application/json",
                        data:_data,
                        complete:function (XMLHttpResquest) {
                            if(XMLHttpResquest.status == 200&& XMLHttpResquest.readyState == 4){
                                alert("答题策略修改成功！");
                                window.history.back();
                            }

                        }

                    })
                }

            }
        })
    })

</script>
</body>
</html>